package cn.iocoder.yudao.module.alipay.controller.admin.infothirdaliapp;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.alipay.controller.admin.infothirdaliapp.vo.*;
import cn.iocoder.yudao.module.alipay.dal.dataobject.infothirdaliapp.InfoThirdAliAppDO;
import cn.iocoder.yudao.module.alipay.convert.infothirdaliapp.InfoThirdAliAppConvert;
import cn.iocoder.yudao.module.alipay.service.infothirdaliapp.InfoThirdAliAppService;

@Tag(name = "管理后台 - 第三方应用信息")
@RestController
@RequestMapping("/alipay/info-third-ali-app")
@Validated
public class InfoThirdAliAppController {

    @Resource
    private InfoThirdAliAppService infoThirdAliAppService;

    @PostMapping("/create")
    @Operation(summary = "创建第三方应用信息")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:create')")
    public CommonResult<Long> createInfoThirdAliApp(@Valid @RequestBody InfoThirdAliAppCreateReqVO createReqVO) {
        return success(infoThirdAliAppService.createInfoThirdAliApp(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新第三方应用信息")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:update')")
    public CommonResult<Boolean> updateInfoThirdAliApp(@Valid @RequestBody InfoThirdAliAppUpdateReqVO updateReqVO) {
        infoThirdAliAppService.updateInfoThirdAliApp(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除第三方应用信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:delete')")
    public CommonResult<Boolean> deleteInfoThirdAliApp(@RequestParam("id") Long id) {
        infoThirdAliAppService.deleteInfoThirdAliApp(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得第三方应用信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:query')")
    public CommonResult<InfoThirdAliAppRespVO> getInfoThirdAliApp(@RequestParam("id") Long id) {
        InfoThirdAliAppDO infoThirdAliApp = infoThirdAliAppService.getInfoThirdAliApp(id);
        return success(InfoThirdAliAppConvert.INSTANCE.convert(infoThirdAliApp));
    }

    @GetMapping("/list")
    @Operation(summary = "获得第三方应用信息列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:query')")
    public CommonResult<List<InfoThirdAliAppRespVO>> getInfoThirdAliAppList(@RequestParam("ids") Collection<Long> ids) {
        List<InfoThirdAliAppDO> list = infoThirdAliAppService.getInfoThirdAliAppList(ids);
        return success(InfoThirdAliAppConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得第三方应用信息分页")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:query')")
    public CommonResult<PageResult<InfoThirdAliAppRespVO>> getInfoThirdAliAppPage(@Valid InfoThirdAliAppPageReqVO pageVO) {
        PageResult<InfoThirdAliAppDO> pageResult = infoThirdAliAppService.getInfoThirdAliAppPage(pageVO);
        return success(InfoThirdAliAppConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出第三方应用信息 Excel")
    @PreAuthorize("@ss.hasPermission('alipay:info-third-ali-app:export')")
    @OperateLog(type = EXPORT)
    public void exportInfoThirdAliAppExcel(@Valid InfoThirdAliAppExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<InfoThirdAliAppDO> list = infoThirdAliAppService.getInfoThirdAliAppList(exportReqVO);
        // 导出 Excel
        List<InfoThirdAliAppExcelVO> datas = InfoThirdAliAppConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "第三方应用信息.xls", "数据", InfoThirdAliAppExcelVO.class, datas);
    }

}
